package uk.co.cocking.getinline2.record;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class TagField implements Field {

	private final String fieldName;
	private final List<String> tags = new ArrayList<String>();
	
	public TagField(String fieldName) {
		this(fieldName, "");
	}

	public TagField(String fieldName, String initialTags) {
		this.fieldName = fieldName;
		if (initialTags.length()> 0) {
			tags.addAll(Arrays.asList(initialTags.split(",")));
		}
	}

	@Override
	public String fieldName() {
		return fieldName;
	}

	@Override
	public String value() {
		return StringUtils.join(tags.toArray(new String[0]),",");
	}
	
	public void addTags(String...newTags) {
		// no duplicates!
		for (String tag: newTags) {
			if (!tags.contains(tag)) {
				tags.add(tag);
			}
		}
	}

}
